package unipd.esp1112.pro;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;


/**
 * Central Activity where the user can decide what to do among 3 choices: 
 * -going to Options Menu
 * -viewing history of his trainings
 * -deciding to start a new training session
 * 
 * @author andrea basso, federico lancerin, alex tomasello
 * 
 */
public class Menu extends Activity {

	/**
	 * variable to store the name of the profile the user is currently using
	 */
	private String nomeProfilo = null;
	
	/**
	 * button that when pressed brings the user to select what kind of new training he want to do
	 */
	private Button nuovaAtt;
	/**
	 * button that when pressed brings the user to view the history of his past trainings
	 */
	private Button storicoAtt;
	/**
	 * button that when pressed brings the user to a new Menu where he can operate on his profile
	 */
	private Button opzioni;
	
	/**
	 * auxiliary variable called from another activity to kill this one and go directly back to profile selection menu
	 */
	public static boolean daTerminare = false;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.centralmenu);

		Intent intent = getIntent();
		nomeProfilo = intent.getStringExtra("profilo");

		TextView benveMenu = (TextView) findViewById(R.id.testoMenuPrincipale);
		benveMenu.setText("Benvenuto " + nomeProfilo);

		nuovaAtt = (Button) findViewById(R.id.nuovaAttivita);
		nuovaAtt.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent myIntent = new Intent(getApplicationContext(), SelezioneAttivita.class);
				myIntent.putExtra("profilo", nomeProfilo);
				startActivity(myIntent);
			}
		});

		storicoAtt = (Button) findViewById(R.id.storicoAttivita);
		storicoAtt.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// CharSequence text = "Ma cossa vutu vedare ?!";
				// int duration = Toast.LENGTH_SHORT;
				// Toast toast = Toast.makeText(getApplicationContext(), text,
				// duration);
				// toast.show();

				Intent myIntent = new Intent(getApplicationContext(), Storico.class);
				myIntent.putExtra("profilo", nomeProfilo);
				startActivity(myIntent);
			}
		});

		opzioni = (Button) findViewById(R.id.opzioni);
		opzioni.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent myIntent = new Intent(getApplicationContext(), Opzioni.class);
				myIntent.putExtra("profilo", nomeProfilo);
				startActivity(myIntent);
			}
		});
	}

	@Override
	public void onResume() {
		super.onResume();
		if (daTerminare) {
			daTerminare = false;
			System.out.println("Menu terminato");
			finish();
		}
	}

}
